package com.gis507.test.CsvSplit;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class CsvSplitDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {

        //1 获取job对象
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        //2 关联Driver类
        job.setJarByClass(CsvSplitDriver.class);

        //3 关联Mapper和Reducer类
        job.setMapperClass(CsvSplitMapper.class);
        job.setReducerClass(CsvSplitReducer.class);

        //4 设置Map的输入输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(CsvBean.class);

        //5	设置最终的输入输出类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(CsvBean.class);

        //6	设置输入输出路径
        FileInputFormat.setInputPaths(job,new Path("D:\\IDEA\\mapreduce\\steam\\input\\steam.csv"));
        FileOutputFormat.setOutputPath(job,new Path("D:\\IDEA\\mapreduce\\steam\\output"));

        //7 提交job
        boolean result = job.waitForCompletion(true);
        System.exit(result?0:1);
    }
}
